package com.java.advance.springmvc.controller;

import com.java.advance.springmvc.annotation.EnjoyAutowired;
import com.java.advance.springmvc.annotation.EnjoyController;
import com.java.advance.springmvc.annotation.EnjoyRequestMapping;
import com.java.advance.springmvc.annotation.EnjoyRequestParam;
import com.java.advance.springmvc.service.JamesService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by aivin on 2019/4/1.
 */
@EnjoyController
@EnjoyRequestMapping(value = "/james")
public class JamesController {


    @EnjoyAutowired(value = "jamesService")
    private JamesService jamesService;


    /**
     * 查询数据
     *
     * @param name
     * @param age
     * @return
     */
    @EnjoyRequestMapping(value = "/query")
    public void query(HttpServletRequest request, HttpServletResponse response,
                      @EnjoyRequestParam(value = "name") String name,
                      @EnjoyRequestParam(value = "age") Integer age) throws IOException {
        PrintWriter printWriter = response.getWriter();
        String result = jamesService.query(name, age);
        printWriter.write(result);
        printWriter.flush();
        printWriter.close();
    }
}
